@extends('admin.base')
@section('title', '首页数据统计')
@section('content')
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/type/index')}}" style="cursor:pointer;" ><cite>首页数据统计</cite></a>;
            </span>
            </div>
        </fieldset>
        <div class="layui-card-body">
            <style>
                table tr td.tc,table tr th.tc {
                    text-align: center;
                    cursor:default;
                }
            </style>
            <table class="layui-table" lay-even lay-size="">
                <colgroup>
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                </colgroup>
                <thead>
                <tr>
                    <th class="tc">描述</th>
                    <th class="tc">实际统计</th>
                    <th class="tc">虚拟统计</th>
                    <th class="tc">状态</th>
                </tr>
                <tbody>
                    @foreach ($list as $v)
                        <tr>
                            <td class="tc">{{$v->name}}</td>
                            <td class="tc">{{ $v->true }}</td>
                            <td class="tc"><a href="javascript:void(0);"
                                   onclick="sorts({{$v->id}},'{{$v->value}}')">{{$v->value}}</a></td>
                            <td class="tc">
                                <form class="layui-form " action="">
                                    <input type="checkbox" @if($v['state']==1) checked @endif name="" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭" value="{{ $v['id'] }}">
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
                </thead>
            </table>
        </div>
    </div>
@endsection
@section('js')
    <script>
        layui.use('form', function(){
            var form = layui.form;

            //搜索
            form.on('submit(selectsub)', function(data){
                let keywords = $('#sub_keywords').val();//关键字
                location.href = "{{url('admin/shop/q_a_store')}}"+"?keywords="+keywords;
                return false;
            });

            //监听指定开关
            form.on('switch(switchTest)', function(data){
                var id = data.value;

                if(data.elem.checked){
                    var state = 1;//启用
                }else{
                    var state = 2;//禁用
                }
                ajax('/admin/total/up_state',{id:id,state:state});
            });
        });

        function sorts(id, num) {
            layer.prompt({
                formType: 3,
                value: num,
                title: '编辑'
            }, function (value, index, elem) {
                var index = layer.load();
                $.post("/admin/total/update", {
                    id: id,
                    num: value,
                    _token: "{{csrf_token()}}"
                }, function (data) {
                    layer.close(index);
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        location.reload();
                    }

                })
            });
        }
    </script>
@endsection